package com.rr.hippo4jdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author RR
 * @date 2024/7/20 21:24
 */
@Configuration
public class DynamicThreadPoolConfig {

    @DynamicThreadPool
    @Bean
    public ThreadPoolExecutor dynamicThreadPoolExecutor() {
        return this.build("dynamicThreadPoolExecutor");
    }

    private ThreadPoolExecutor build(String name) {
        ThreadPoolExecutor messageConsumeDynamicExecutor = ThreadPoolBuilder.builder()
                .threadFactory(name)
                .threadPoolId(name)
                .dynamicPool()
                .build();
        return messageConsumeDynamicExecutor;
    }

}
